<?php

/**
 * Function for job_opportunity_details()
 * @return string
 */
function job_opportunity_details(){
  global $base_url,$language;
  $Path = drupal_get_path('module', 'employment');
  drupal_add_css($Path.'/css/employment.css');
  drupal_set_title('Job Opportunities');
  my_db_change(1);
  $query = new EntityFieldQuery();
  $query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'job_opportunity')
    ->propertyCondition('status',1)
    ->propertyCondition('language', $language->language, '=')
    ->fieldOrderBy('field_job_date','value','DESC')
    ->propertyOrderBY('title','ASC');
  $result = $query->execute();

  $nid = current($result['node']);

  if (isset($result['node'])) {
    $news_items_nids = array_keys($result['node']);
    $news_items = entity_load('node', $news_items_nids);
  }
//print "<pre>";print_r($news_items);print "</pre>";
  my_db_change(0);
  $output = theme('employment_theme_job',array('items' => $news_items,'nid'=>$nid));
  return $output;
}

/*
 *
 * Functuion for employment Details
 */
function employment_details (){
  global $base_url,$language;
  $Path = drupal_get_path('module', 'employment');
  drupal_add_css($Path.'/css/employment.css');

  $title ="<div class='school_heading'><strong>Employment</strong></div>";
  $title .="<div class='contentarial_grey1'></div>";
  $title .="<div class='school_heading1'><strong>Directorate of Employment and Training</strong></div>";
  $title .="<div class='school_heading2'>Information on Cut-off Seniority dates adopted for nomination <br> in Employment Offices in Tamil Nadu</div>";
  //$title .="<div class='school_heading2'>In Employment Offices In Tamil Nadu</div>";
  $title .="<div class='school_heading3'>	(August - 2014)</div>";

  $title .="<p align = 'center'>";
  $title .="<a target ='_blank' href = 'http://tnvelaivaaippu.gov.in/Empower/'>";

  $title .="<img width ='235' height ='25' border ='0'src = '".$base_url."/sites/all/modules/employment/images/emp_online.gif' class='emp_cent'>";

  $title .="<a target ='_blank' href = '../sites/default/files/list_VIC_TRB_021214.pdf'><div class='school_heading2'>List of Candidates nominated for the Post of Vocational Instructor(Computer)notified by Teacher's Recruitment Board</div></a>";

  $title .="<a target ='_blank' href = '../sites/default/files/emp_statistics_300914.pdf'><div class='school_heading2'>Employment Exchange Statistics - Community-wise  break up of Job Seekers waiting on the rolls of Employment Exchanges in Tamilnadu as on 30th September 2014</div></a>";


  $title .="</a>";
  $title .="</p>";

  my_db_change(1);
  //$qry = db_query("select c.field_test_dist_value,f.filepath from content_type_employment_details as c join node as n on c.nid=n.nid and n.vid=c.vid and n.status=1 and n.nid NOT IN ('39272','39274','39313','39314','39328','39329','39330','39331','39334','39335','39338','39339','39340','39341','39342','39362','39343','39344','39345','39356','40493') left join files as f on f.fid=c.field_test_file_upload_fid");
  $query = new EntityFieldQuery();
  $query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'employment_details')
    ->propertyCondition('status',1)
    ->propertyCondition('nid', array('39272','39274','39313','39314','39328','39329','39330','39331','39334','39335','39338','39339','39340','39341','39342','39362','39343','39344','39345','39356','40493'), "NOT IN")
    //->fieldCondition('field_category', 'value', 'District', '=')
    ->propertyOrderBY('title','ASC');
  $result = $query->execute();

  if (isset($result['node'])) {
    $news_items_nids = array_keys($result['node']);
    $news_items = entity_load('node', $news_items_nids);
  }
  //return print_r($news_items);
  my_db_change(0);
  $output ="<table width='500' border='1' align='center'><tr>";
  $i = 1;
  foreach($news_items as $row){
    $name = ($row->field_emp_district) ? $row->field_emp_district['und'][0]['value'] : '';
	//return print_r($name);
    if($row->field_file_emp_upload && $row->field_file_emp_upload['und'][0]['uri']) {
    	$link = $row->field_file_emp_upload['und'][0]['uri'];
    	$wrapper = file_stream_wrapper_get_instance_by_uri($link);
    	if($wrapper == true){
    		 $filepath = $wrapper->getDirectoryPath() . "/" . file_uri_target($link);
    	}
    	$filepath="http://cms.tn.gov.in/tncms_latest/$filepath";
    }
    $output .='<td width="400"><a href="javascript:void(0);" onclick="return tnportal_window('. $filepath .');" >'.$name.'</a></td>';
    if($i%3 == 0)
    {
    $output .= '</tr><tr>';
    }
    $i++;
  }
  $output .="</tr></table><br>";



  $title1 ="<p align = 'center'>";
  $title1 .="<a target ='_blank' href = 'http://www.tn.gov.in/acts-rules/employment/empexg-act.htm'>";
  $title1 .="<img width ='235' height ='25' border ='0 'src = '".base_path()."sites/all/modules/employment/images/emp_act.gif' class='emp_cent'>";
  $title1.="</a>";
  $title1 .="</p>";
  $output2 = '';

  my_db_change(1);
  //$qry_title2 = db_query("select n.title,c.field_test_state_value,f.filepath from content_type_employment_details as c join node as n on c.nid=n.nid and n.status=1 and n.vid=c.vid left join files as f on f.fid=c.field_test_file_upload_fid where n.nid in ('39313','39314','39328','39329','39330','39331','39334','39335','39338','39339','39341','39362','39345')");
  $query_2 = new EntityFieldQuery();
  $query_2->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'employment_details')
    ->propertyCondition('status',1)
    ->propertyCondition('nid', array('39313','39314','39328','39329','39330','39331','39334','39335','39338','39339','39341','39362','39345'), "IN")
    //->fieldCondition('field_category', 'value', 'District', '=')
    ->propertyOrderBY('title','ASC');
  $result_2 = $query_2->execute();

  if (isset($result_2['node'])) {
    $news_items_nids_2 = array_keys($result_2['node']);
    $news_items_2 = entity_load('node', $news_items_nids_2);
  }
  my_db_change(0);

  foreach($news_items_2 as $row2){
    if($row2->field_file_emp_upload['und'][0]['uri']) {
      	$link_2 = $row2->field_file_emp_upload['und'][0]['uri'];
      	$wrapper_2 = file_stream_wrapper_get_instance_by_uri($link_2);
      	if($wrapper_2 == true){
      		 $filepath_2 = $wrapper_2->getDirectoryPath() . "/" . file_uri_target($link);
      	}
      	$filepath_2 ="http://cms.tn.gov.in/tncms_latest/$filepath_2";
    }
    	$name2 = $row2->title;
    	$state2 = $row2->field_emp_state['und'][0]['value'];
    	$output2 .='<div class = "title_emp"><a href ="'.$filepath_2.'" target = "_blank"><strong>'.$name2.'</strong></a></div><div class="clr"></div>';
    	//echo $output2;
  }
  $bot3 ="<p><b><i><u class='emp_it'>List of Candidates nominated for the post of Secondary Grade Teacher</p></i></b></u>";

  my_db_change(1);
	//$qry_title4 = db_query("select n.title,c.field_test_state_value,f.filepath from content_type_employment_details as c join node as n on c.nid=n.nid and n.status=1 and n.vid = c.vid left join files as f on f.fid=c.field_test_file_upload_fid where n.nid in ('39340','39342','39343','39344','40493')");
  $query_3 = new EntityFieldQuery();
  $query_3->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'employment_details')
    ->propertyCondition('status',1)
    ->propertyCondition('nid', array('39340','39342','39343','39344','40493'), "IN")
    //->fieldCondition('field_category', 'value', 'District', '=')
    ->propertyOrderBY('title','ASC');
  $result_3 = $query_3->execute();

  if (isset($result_3['node'])) {
    $news_items_nids_3 = array_keys($result_3['node']);
    $news_items_3 = entity_load('node', $news_items_nids_3);
  }
    my_db_change(0);

    foreach($news_items_3 as $row3){
      if($row3->field_file_emp_upload['und'][0]['uri']) {
        	$link_3 = $row3->field_file_emp_upload['und'][0]['uri'];
        	$wrapper_3 = file_stream_wrapper_get_instance_by_uri($link_3);
        	if($wrapper_3 == true){
        		 $filepath_3 = $wrapper_3->getDirectoryPath() . "/" . file_uri_target($link_3);
        	}
        	$filepath_3 ="http://cms.tn.gov.in/tncms_latest/$filepath_3";
      }
	  $name3 = $row3->title;
	  $output3 .='<div class = "title_emp"><a href ="'.$filepath_3.'" target = "_blank"><strong>'.$name3.'</strong></a></div><div class="clr"></div>';
	  //echo $output2;
	}


	$bot2 .= "<p><i class='emp_it'>For further enquiry the candidates may contact the Teachers Recruitment Board by referring their Nomination ID in the list.  Candidates who come within the Cut off date and if their names are omitted may contact the District Employment Office concerned.</p></I>";

    my_db_change(1);
	//$qry_title3 = db_query("select n.title,c.field_test_state_value,f.filepath from content_type_employment_details as c join node as n on c.nid=n.nid and n.vid=c.vid and n.status=1 left join files as f on f.fid=c.field_test_file_upload_fid where n.nid in ('39356')");
  $query_4 = new EntityFieldQuery();
  $query_4->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'employment_details')
    ->propertyCondition('status',1)
    ->propertyCondition('nid', array('39356'), "IN")
    //->fieldCondition('field_category', 'value', 'District', '=')
    ->propertyOrderBY('title','ASC');
  $result_4 = $query_4->execute();

  if (isset($result_4['node'])) {
    $news_items_nids_4 = array_keys($result_4['node']);
    $news_items_4 = entity_load('node', $news_items_nids_4);
  }
    my_db_change(0);

    foreach($news_items_4 as $row4){
      if($row4->field_file_emp_upload['und'][0]['uri']) {
        	$link_4 = $row4->field_file_emp_upload['und'][0]['uri'];
        	$wrapper_4 = file_stream_wrapper_get_instance_by_uri($link_4);
        	if($wrapper_4 == true){
        		 $filepath_4 = $wrapper_4->getDirectoryPath() . "/" . file_uri_target($link_4);
        	}
        	$filepath_4 ="http://cms.tn.gov.in/tncms_latest/$filepath_4";
      }
	$name4 = $row4->title;
	$output4 .='<div class = "title_emp"><a href ="'.$filepath_4.'" target = "_blank"><strong>'.$name4.'</strong></a></div><div class="clr"></div>';
	}


  return $title.$output.$title1.$output2.$bot3.$output3.$bot2.$output4;
}




















?>